package com.coder.rental.utils;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author: zhanglin
 * @description: redis工具类-设置-获取-删除
 * @date 2025/3/20
 */
@Component
public class RedisUtils {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    /*
    * 设置值
    * key 键
    * value 值
    * timeout 超市时间
    * */
    public void set(String key,String value,Long timeout){
        stringRedisTemplate.opsForValue().set(key,value,timeout, TimeUnit.SECONDS);
    }
    /*
    * 获取键
    * key 键
    * return 返回值
    * */
    public String get(String key){
        return stringRedisTemplate.opsForValue().get(key);
    }
    /*
    * 删除键
    * key 键
    * */
    public void del(String key){
        stringRedisTemplate.delete(key);
    }

    
    
}
